<template>
  <iframe
    id="iframe"
    ref="iframe"
    draggable="false"
    frameBorder="0"
    :style="`width: 100%; height: 100%; border: none`"
    :src="src"
    @load="registeListener"
  />
  <!-- 线上地址 http://30.30.2.14/dist/scene-test/index.html -->
</template>

<script>
export default {
  data() {
    return {
      iframe: null,
      isReady: false
    };
  },

  computed: {
    src() {
      return process.env.NODE_ENV === 'development' ? '/scene-test/index.html' : 'http://30.30.2.14/dist/scene-test/index.html';
    }
  },

  created() {
    this.height = window.screen.height;
  },

  mounted() {
    this.iframe = this.$refs['iframe'];
    this.iframe.addEventListener('message', this.registeListener);
  },

  methods: {
    //   注册监听事件
    registeListener() {
      const iframe = document.getElementById('iframe');
      iframe.contentWindow.onWebEngineBridgeInit = (WebEngineBridge) => {
        this.$store.commit('setData', { name: 'WebEngineBridge', value: WebEngineBridge });
      };
    }

  }
};
</script>

<style lang="scss" scoped>
#iframe {
  z-index: 0;
  position: fixed;
  top: 0;
}
</style>
